Research
Security News
Threat Actor Exposes Playbook for Exploiting npm to Build Blockchain-Powered Botnets
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
external-ip
Advanced tools
external-ip
is a node.js library to get your external ip from multiple services.
npm install external-ip
basic
'use strict';
const getIP = require('external-ip')();
getIP((err, ip) => {
if (err) {
// every service in the list has failed
throw err;
}
console.log(ip);
});
with configuration
'use strict';
const extIP = require('external-ip');
let getIP = extIP({
replace: true,
services: ['https://ipinfo.io/ip', 'http://ifconfig.co/x-real-ip', 'http://ifconfig.io/ip'],
timeout: 600,
getIP: 'parallel',
userAgent: 'Chrome 15.0.874 / Mac OS X 10.8.1'
});
getIP((err, ip) => {
if (err) {
throw err;
}
console.log(ip);
});
The API of this library is designed around the classic node.js error-first callback. As of node.js V8, converting this type of callback into a promise is pretty straight forward and requires one more line of code.
basic
'use strict';
const {promisify} = require('util'); //<-- Require promisify
const getIP = promisify(require('external-ip')()); // <-- And then wrap the library
getIP().then((ip)=> {
console.log(ip);
}).catch((error) => {
console.error(error);
});
with configuration
'use strict';
const { promisify } = require('util'); //<-- Require promisify
const getIP = promisify(require('external-ip')({
replace: true,
services: ['https://ipinfo.io/ip', 'http://icanhazip.com/', 'http://ident.me/'],
timeout: 600,
getIP: 'parallel',
verbose: true
})); // <-- And then wrap the library
getIP().then((ip) => {
console.log(ip);
}).catch((error) => {
console.error(error);
});
If you believe this extra step shouldn't be there, feel free to open an issue and/or a pull request.
require('external-ip')
returns a constructor function that accepts an optional configuration object.
It can be used to create multiple instances with different configuration if necessary
Array
of urls that return the ip in the html body, required if replace is set to trueBoolean
if true, replaces the internal array of services with the user defined, if false, extends it, default: false
1000
'sequential'
Makes a request to the first url in the list, if that fails sends to the next and so on. 'parallel'
Makes requests to all the sites in the list, on the first valid response all the pending requests are canceled, default: 'sequential'
String
Set a custom User-Agent
header, default: curl/
Boolean
Log additional information to the console, default: false
Returns the configured getIP instance.
The callback gets 2 arguments:
install as a global package with npm install -g external-ip
.
$ external-ip -h
Usage: external-ip [options]
Options:
-h, --help output usage information
-V, --version output the version number
-R, --replace replace internal services instead of extending them.
-s, --services <url> service url, see examples, required if using -R
-t, --timeout <ms> set timeout per request
-P, --parallel set to parallel mode
-u, --userAgent <User-Agent> provide a User-Agent header, default: curl/
-v, --verbose provide additional details
This program prints the external IP of the machine.
All arguments are optional.
Examples:
$ external-ip
$ external-ip -P -t 1500 -R -s http://icanhazip.com/ -s http://ident.me/
Default services:
http://icanhazip.com/
http://ident.me/
http://tnx.nl/ip
http://myip.dnsomatic.com/
http://ipecho.net/plain
http://diagnostic.opendns.com/myip
Documentation can be found at https://github.com/J-Chaniotis/external-ip
Change your working directory to the project's root, npm install
to get the development dependencies and then run npm test
FAQs
A node.js library to get your external ip from multiple services
We found that external-ip demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
Security News
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
Security News
Research
A malicious npm package disguised as a WhatsApp client is exploiting authentication flows with a remote kill switch to exfiltrate data and destroy files.